package com.matrix.java.chap_05;

import java.util.Scanner;

/*
    统计正教和负数的个数然后计算这些数的平均值
 */
public class Ex5_01 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter an integer, the input ends if it is 0: ");
        int positiveNum = 0;
        int negativeNum = 0;
        int total = 0;
        int count = 0;
        int inputNum = input.nextInt();
        if (inputNum == 0) {
            System.out.println("No numbers are entered except 0");
            return;
        } else {
            do {
                if (inputNum > 0) {
                    positiveNum++;
                } else if (inputNum < 0) {
                    negativeNum++;
                } else {
                    break;
                }
                total += inputNum;
                count++;
                inputNum = input.nextInt();
            } while (inputNum != 0);
        }
        double average = (double) total / count;
        System.out.println("The number of positives is " + positiveNum);
        System.out.println("The number of negatives is " + negativeNum);
        System.out.println("The total is " + total);
        System.out.println("The average is " + average);
        input.close();
    }
}
